package org.androidpn.server.console.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.androidpn.server.dao.MessageDao;
import org.androidpn.server.dao.hibernate.MessageDaoImpl;
import org.androidpn.server.model.Message;
import org.androidpn.server.service.MessageService;
import org.androidpn.server.service.ServiceLocator;
import org.androidpn.server.util.TreeGrid;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/addController")
public class AddMessageController{
	
	private MessageService messageService;
	
	public AddMessageController(){
		messageService = ServiceLocator.getMessageService();
	}
	@RequestMapping(params = "add")
	public ModelAndView list(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return new ModelAndView("user/add");
	}
	/*@RequestMapping(params = "messageList")
	public List<TreeGrid> messageList(HttpServletRequest request,
			HttpServletResponse response){
		List<Message> list = messageService.getAllMessage();
		List<TreeGrid> message = new ArrayList<TreeGrid>();
		if(message.size()>0){
			for(Message m : list){
				TreeGrid treeGrid = new TreeGrid();
				treeGrid.setText(m.getMessage());
				message.add(treeGrid);
			}
		}
		return message;
	}*/
	
	/*public void responseDatagrid(HttpServletResponse response,
			JSONObject jObject) {
		
		response.setHeader("Cache-Control", "no-store");
		try {
			PrintWriter pw = response.getWriter();
			response.setContentType("application/json");
			pw.write(jObject.toString());
			pw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}*/
}
